import { addressList } from '../../utils/api'
const state = {
    list: [],

}

const mutations = {
    changelist(state, arr) {
        state.list = arr
    },
}

const actions = {
    reqchangelist(context) {
        let users = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {};
        addressList({ uid: users.uid }).then(res => {
            //console.log(res.data.list);
            let lists = res.data.list ? res.data.list : []
            lists.map(item => {
                return (item.name = item.username), (item.tel = item.userphone), (item.address = item.location + item.useraddress)
            })
            context.commit('changelist', lists)
        })
    },

}

const getters = {
    list(state) {
        return state.list
    },
}

export default {
    state,
    actions,
    mutations,
    getters,
    namespaced: true
}